import blue
import uix
import base
import uicls
import uiutil
import uiconst

class Message(uicls.Container):
    __guid__ = 'uicls.Message'

    def _Initialize(self, *args, **kw):
        uicls.Container._Initialize(self, *args, **kw)
        self.inity = 150
        self.scope = 'station_inflight'
        self.message = None



    def Prepare_Text_(self):
        self.message = uicls.Label(text='', parent=self, left=6, top=3, autowidth=False, width=288, fontsize=12, state=uiconst.UI_DISABLED)



    def Prepare_Underlay_(self):
        self.children.append(blue.os.LoadObject('res:/UI/Component/hint_underlay.blue'))



    def ShowMsg(self, text):
        if (self.message is None):
            self.Prepare_Text_()
            self.Prepare_Underlay_()
        self.message.text = ('<center>' + text)
        self.SetAlign(uiconst.CENTERTOP)
        self.SetSize(300, (self.message.textheight + 8))
        offset = sm.GetService('window').GetCameraLeftOffset(self.width, align=uiconst.CENTERTOP, left=0)
        self.SetPosition(offset, (int((uicore.desktop.height * 0.1666)) + 32))
        self.state = uiconst.UI_DISABLED
        uiutil.SetOrder(self, 0)
        self.timer = base.AutoTimer(5000, self.hide)



    def hide(self):
        if ((self is not None) and (not self.destroyed)):
            self.state = uiconst.UI_HIDDEN



    def kill_timer(self):
        self.timer = None




